<template>
  <div class="card content-box">
    <div class="table-box">
      <ProTable ref="proTable" :columns="columns" :request-api="getTableList">
        <!-- 表格 header 按钮 -->
        <template #tableHeader>
          <el-button v-auth="'sys:sys_log:export'" type="primary" :icon="Download" plain @click="exportExcel">导出</el-button>
        </template>
        <!-- 菜单操作 -->
        <!--        <template #operation="scope">-->
        <!--        </template>-->
      </ProTable>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Download } from "@element-plus/icons-vue";
import ProTable from "@/components/ProTable/index.vue";
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
import { exportSysLogExcel, getSysLogPage } from "@/api/modules/sys/SysLog";
import { ref } from "vue";
import { useDownload } from "@/hooks/useDownload";
import { getDictItem } from "@/api/modules/sys/dict";

// 表格配置项
const columns: ColumnProps[] = [
  // { type: "selection", fixed: "left", width: 70 },
  {
    prop: "logName",
    label: "日志名称",
    search: { el: "input", tooltip: "日志名称" },
    fixed: "left"
  },
  {
    prop: "ip",
    label: "请求ip",
    fixed: "left"
  },
  {
    prop: "url",
    label: "请求url",
    fixed: "left"
  },
  {
    prop: "method",
    label: "请求方法"
  },
  {
    prop: "methodName",
    label: "执行方法名称",
    width: 400
  },
  {
    prop: "succeed",
    label: "是否执行成功",
    tag: true,
    enum: () => getDictItem("yesOrNo"),
    search: { el: "select-v2", tooltip: "是否成功" }
  },
  {
    prop: "error",
    label: "错误信息"
  },
  {
    prop: "paramsJson",
    label: "请求参数"
  },
  {
    prop: "resultJson",
    label: "执行结果"
  },
  {
    prop: "duration",
    label: "执行耗时(ms)"
  },
  {
    prop: "createTime",
    label: "创建时间",
    fixed: "right"
  }
  // { prop: "operation", label: "操作", fixed: "right" }
];

const proTable = ref<ProTableInstance>();

const getTableList = param => {
  return getSysLogPage(param);
};

const exportExcel = async () => {
  useDownload(exportSysLogExcel, proTable.value?.searchParam);
};
</script>
